package com.liwalla.domain;

import com.liwalla.domain.Disease;
import com.liwalla.domain.KidDataOnDemand;
import java.util.List;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

privileged aspect DiseaseDataOnDemand_Roo_DataOnDemand {
    
    declare @type: DiseaseDataOnDemand: @Component;
    
    private Random DiseaseDataOnDemand.rnd = new java.security.SecureRandom();
    
    private List<Disease> DiseaseDataOnDemand.data;
    
    @Autowired
    private KidDataOnDemand DiseaseDataOnDemand.kidDataOnDemand;
    
    public Disease DiseaseDataOnDemand.getNewTransientDisease(int index) {
        com.liwalla.domain.Disease obj = new com.liwalla.domain.Disease();
        obj.setDescription("description_" + index);
        obj.setFinalDate(new java.util.Date());
        obj.setInitialDate(new java.util.Date());
        obj.setKid(kidDataOnDemand.getRandomKid());
        obj.setName("name_" + index);
        obj.setSymptom("symptom_" + index);
        return obj;
    }
    
    public Disease DiseaseDataOnDemand.getSpecificDisease(int index) {
        init();
        if (index < 0) index = 0;
        if (index > (data.size()-1)) index = data.size() - 1;
        Disease obj = data.get(index);
        return Disease.findDisease(obj.getId());
    }
    
    public Disease DiseaseDataOnDemand.getRandomDisease() {
        init();
        Disease obj = data.get(rnd.nextInt(data.size()));
        return Disease.findDisease(obj.getId());
    }
    
    public boolean DiseaseDataOnDemand.modifyDisease(Disease obj) {
        return false;
    }
    
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void DiseaseDataOnDemand.init() {
        if (data != null) {
            return;
        }
        
        data = com.liwalla.domain.Disease.findDiseaseEntries(0, 10);
        if (data == null) throw new IllegalStateException("Find entries implementation for 'Disease' illegally returned null");
        if (data.size() > 0) {
            return;
        }
        
        data = new java.util.ArrayList<com.liwalla.domain.Disease>();
        for (int i = 0; i < 10; i++) {
            com.liwalla.domain.Disease obj = getNewTransientDisease(i);
            obj.persist();
            data.add(obj);
        }
    }
    
}
